// Copyright (c) 2011 SameGoal LLC.
// All Rights Reserved.
// Author: Andy Hochhaus <ahochhaus@samegoal.com>

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef NET_HTTP_SERVER_COMET_SESSION_MANAGER_H_
#define NET_HTTP_SERVER_COMET_SESSION_MANAGER_H_

#include <map>
#include <memory>
#include <string>
#include <vector>
#include <unordered_map>  // NOLINT: C++11 not recognized as C++ header

#include "net/http/server/comet/session.h"

namespace sg {
namespace net {
namespace http {
namespace server {
namespace comet {

class CometServer;

class SessionManager {
 public:
  typedef std::shared_ptr<Session> SessionRefCntPtr;

  static SessionRefCntPtr New(CometServer *server);
  static SessionRefCntPtr GetSession(const std::string &sid);
  static void Remove(const std::string &sid);
  static void Terminate();

  typedef std::unordered_map<const std::string,
                             SessionRefCntPtr,
                             std::hash<std::string> > SessionMap;
  static SessionMap *session_map_;
  static std::mutex *mutex_;
};

}  // namespace comet
}  // namespace server
}  // namespace http
}  // namespace net
}  // namespace sg

#endif  // NET_HTTP_SERVER_COMET_SESSION_MANAGER_H_
